<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise</title>
</head>

<body>
    <script src="./js/jquery.js"></script>
    <script>
        // getUsers({id:2},function(res){
        //     getUsers({id:3},function(res){
        //         getUsers({id:4},function(res){
        //             getUsers({id:5},function(){

        //             })
        //         })
        //     })
        // })

        // $.get("http://wangsr.vip:3001/test/t1", function (res) {
        //     $.get("http://wangsr.vip:3001/test/t2", { id: res.id }, function (res) {
        //         $.get("http://wangsr.vip:3001/test/t3", { id: res.id }, function (res) {
        //             console.log(res)
        //         })
        //     })
        // })
        // console.log('abc')
        $.get("http://wangsr.vip:3001/test/t1", function (res) {
            console.log('ajax请求成功返回数据')
            // console.log('abd')
        })
        let promise = new Promise(function (resolve, reject) {
            $.get("http://wangsr.vip:3001/test/t1", function (res) {
                resolve(res)
            })
        })

        // promise
        // .then(function(value){
        //     console.log('请求成功了')
        //     console.log(value)
        // })
        // .then()
        function request(url,data){
            const p =  new Promise((resolve,reject) => {
                $.ajax(url,{
                    data:data,
                    success:function(data){
                        resolve(data)
                    },
                    error:function(xhr,textStatus){
                        reject(textStatus)
                    }
                })
            })
            return p
        }
        request("http://wangsr.vip:3001/test/t1")
        .then((res) => {return request("http://wangsr.vip:3001/test/t5",res)})
        .then((res => {return request("http://wangsr.vip:3001/test/t3",res)}))
        .then((res) => {console.log(res)})
        .catch((err) => {
            console.log('请求出现出错')
            console.log(err)
        })
        // $.post('http://baidu.com',{id:1,a:2})
        // xhr.send('id=1&a=2')
        // $.post("http://wangsr.vip:3001/test/t1",{a:1,b:2}).then(res => console.log(res))
    </script>

</body>

</html>